package com.yxp.offer;

public class Problem64 {

    private int sum;

    public static void main(String[] args) {
        Problem64 problem64 = new Problem64();
        System.out.println(problem64.sumNum2(9));
    }

    public int sumNums(int n) {
        int temp = 0;
        for (int i = 1; i <= n; i++) {
            temp = temp + i;
        }
        return temp;
    }

    public int sumNums1(int n) {
//        return (1 + n) * n / 2;
        return ((1 + n) * n) >> 1;
    }

    public int sumNum2(int n){
        return n == 0 ? 0 : n + sumNum2(n - 1);
    }
}
